#include "homedevform.h"
#include "ui_homedevform.h"

#include "globalvars.h"
#include <QStringBuilder>

HomeDevForm::HomeDevForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HomeDevForm)
{
    ui->setupUi(this);

    m_devStatuTimer = new QTimer(this);
    connect(m_devStatuTimer, SIGNAL(timeout()),
            this, SLOT(slotDevStatuTIM()));
    m_devStatuTimer->start(500);
}

HomeDevForm::~HomeDevForm()
{
    delete ui;
}

void HomeDevForm::slotDevStatuTIM(void)
{
    ///定时获取设备控制状态
    QString msg = QString(CMD_DevStat_S)
            % QString("#") % GlobalVars::g_localUsrInfo.getID();
    emit signalSendMsg(msg);
}

void HomeDevForm::slotParseDevStat(QString data)
{
    QStringList list = data.split("|");
    if(list.at(0) == "0")
    {
        ui->tb_hallLED->setStyleSheet("border-image: url(:/images/led_off.png);");
    }else
    {
        ui->tb_hallLED->setStyleSheet("border-image: url(:/images/led_on.png);");
    }

    if(list.at(1) == "0")
    {
        ui->tb_bedRoomLED->setStyleSheet("border-image: url(:/images/led_off.png);");
    }else
    {
        ui->tb_bedRoomLED->setStyleSheet("border-image: url(:/images/led_on.png);");
    }

    if(list.at(2) == "0")
    {
        ui->tb_kotcheLED->setStyleSheet("border-image: url(:/images/led_off.png);");
    }else
    {
        ui->tb_kotcheLED->setStyleSheet("border-image: url(:/images/led_on.png);");
    }

    if(list.at(3) == "0")
    {
        ui->tb_lavLED->setStyleSheet("border-image: url(:/images/led_off.png);");
    }else
    {
        ui->tb_lavLED->setStyleSheet("border-image: url(:/images/led_on.png);");
    }

    if(list.at(4) == "0")
    {
        ui->tb_beep->setStyleSheet("border-image: url(:/images/beep_off.png);");
    }else
    {
        ui->tb_beep->setStyleSheet("border-image: url(:/images/beep_on.png);");
    }
}

void HomeDevForm::on_tb_hallLED_clicked()
{
    QString msg = QString(CMD_DevLeds_D)
            % QString("#") % "1";
    emit signalSendMsg(msg);
}

void HomeDevForm::on_tb_bedRoomLED_clicked()
{
    QString msg = QString(CMD_DevLeds_D)
            % QString("#") % "2";
    emit signalSendMsg(msg);
}

void HomeDevForm::on_tb_kotcheLED_clicked()
{
    QString msg = QString(CMD_DevLeds_D)
            % QString("#") % "3";
    emit signalSendMsg(msg);
}

void HomeDevForm::on_tb_lavLED_clicked()
{
    QString msg = QString(CMD_DevLeds_D)
            % QString("#") % "4";
    emit signalSendMsg(msg);
}

void HomeDevForm::on_tb_beep_clicked()
{
    QString msg = QString(CMD_DevBeep_B)
            % QString("#");
    emit signalSendMsg(msg);
}

void HomeDevForm::on_pb_send_clicked()
{

}
